home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
borland
/
prbgi097.zip
/
BGIDEMO.INC
< prev
next >
Wrap
Text File
|
1992-12-15
|
38KB
|
1,255 lines
#include <STDio.h>
#include <CONIO.h>
#include <math.h>
#include <DOS.h>
#ifdef _cplusplus
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#define TRUE 1 /* Define some handy constants */
#define FALSE 0 /* Define some handy constants */
#define PI 3.14159 /* Define a value for PI */
#define ON 1 /* Define some handy constants */
#define OFF 0 /* Define some handy constants */
char *Fonts[] = {
"DefaultFont", "TriplexFont", "SmallFont",
"SansSerifFont", "GothicFont"
};
char *LineStyles[] = {
"SolidLn", "DottedLn", "CenterLn", "DashedLn", "UserBitLn"
};
char *FillStyles[] = {
"EmptyFill", "SolidFill", "LineFill", "LtSlashFill",
"SlashFill", "BkSlashFill", "LtBkSlashFill", "HatchFill",
"XHatchFill", "InterleaveFill", "WideDotFill", "CloseDotFill"
};
char *TextDirect[] = {
"HorizDir", "VertDir"
};
char *HorizJust[] = {
"LeftText", "CenterText", "RightText"
};
char *VertJust[] = {
"BottomText", "CenterText", "TopText"
};
struct PTS {
int x, y;
}; /* Structure to hold vertex points */
int xasp_,yasp_;
int ErrorCode; /* Reports any graphics errors */
/* */
/* REPORTSTATUS: Report the current configuration of the system */
/* after the auto-detect initialization. */
/* */
int ReportStatus(void far * GraphDriverPtr)
{
struct viewporttype viewinfo; /* Params for inquiry procedures*/
struct linesettingstype lineinfo;
struct fillsettingstype fillinfo;
struct textsettingstype textinfo;
struct palettetype palette;
const char *driver, *mode; /* Strings for driver and mode */
int x, y;
int xRes,yRes;
getviewsettings( &viewinfo );
getlinesettings( &lineinfo );
getfillsettings( &fillinfo );
gettextsettings( &textinfo );
getpalette( &palette );
x = 10;
y = 4;
MainWindow( "Status report after InitGraph" );
settextjustify( LEFT_TEXT, TOP_TEXT );
driver = getdrivername();
mode = BGI_getmodename(BGI_getgraphmode(0)); /* get current setting */
gprintf( &x, &y, "Graphics device : %-20s (%d)", driver, *(int*)GraphDriverPtr );
gprintf( &x, &y, "Graphics mode : %-20s (%d)", mode, BGI_getgraphmode(0) );
gprintf( &x, &y, "Screen resolution : ( 0, 0, %d, %d )", getmaxx(), getmaxy() );
gprintf( &x, &y, "Current view port : ( %d, %d, %d, %d )",
viewinfo.left, viewinfo.top, viewinfo.right, viewinfo.bottom );
gprintf( &x, &y, "Clipping : %s", viewinfo.clip ? "ON" : "OFF" );
gprintf( &x, &y, "Current position : ( %d, %d )", getx(), gety() );
gprintf( &x, &y, "Colors available : %d", MaxColors );
gprintf( &x, &y, "Current color : %d", getcolor() );
gprintf( &x, &y, "Line style : %s", LineStyles[ lineinfo.linestyle ] );
gprintf( &x, &y, "Line thickness : %d", lineinfo.thickness );
gprintf( &x, &y, "Current fill style : %s", FillStyles[ fillinfo.pattern ] );
gprintf( &x, &y, "Current fill color : %d", fillinfo.color );
gprintf( &x, &y, "Current font : %s", Fonts[ textinfo.font ] );
gprintf( &x, &y, "Text direction : %s", TextDirect[ textinfo.direction ] );
gprintf( &x, &y, "Character size : %d", textinfo.charsize );
gprintf( &x, &y, "Horizontal justify : %s", HorizJust[ textinfo.horiz ] );
gprintf( &x, &y, "Vertical justify : %s", VertJust[ textinfo.vert ] );
if ( BGI_getresolution(&xRes,&yRes) == 0 )
{
gprintf( &x, &y, "X resolution [ppi] : %d", xRes );
gprintf( &x, &y, "Y resolution [ppi] : %d", yRes );
}
Pause(); /* Pause for user to read screen*/
return(0);
}
int static Textfont;
int TextDump2(void far * UnusedPointer)
{
static int CGASizes[] = {
1, 3, 7, 3, 3 };
static int NormSizes[] = {
1, 4, 7, 4, 4 };
char buffer[80];
int ch, wwidth, lwidth, size;
struct viewporttype vp;
sprintf( buffer, "%s Character Set", Fonts[Textfont] );
MainWindow( buffer ); /* Display fontname as banner */
getviewsettings( &vp ); /* read current viewport */
settextjustify( LEFT_TEXT, TOP_TEXT );
moveto( 2, 3 );
buffer[1] = '\0'; /* Terminate string */
wwidth = vp.right - vp.left; /* Determine the window width */
lwidth = textwidth( "H" ); /* Get average letter width */
if( Textfont == DEFAULT_FONT ){
changetextstyle( Textfont, HORIZ_DIR, 1 );
ch = 0;
while( ch < 256 ){ /* For each possible character */
buffer[0] = ch; /* Put character into a string */
outtext( buffer ); /* send string to screen */
if( (getx() + lwidth) > wwidth )
moveto( 2, gety() + textheight("H") + 3 );
++ch; /* Goto the next character */
}
}
else{
size = (MaxY < 200) ? CGASizes[Textfont] : NormSizes[Textfont];
changetextstyle( Textfont, HORIZ_DIR, size );
ch = '!'; /* Begin at 1st printable */
while( ch < 127 ){ /* For each printable character */
buffer[0] = ch; /* Put character into a string */
outtext( buffer ); /* send string to screen */
if( (lwidth+getx()) > wwidth ) /* Are we still in window? */
moveto( 2, gety()+textheight("H")+3 );
++ch; /* Goto the next character */
}
}
Pause(); /* Pause until user acks */
return(0);
} /* end of TextDump2 */
/* */
/* TEXTDUMP: Display the all the characters in each of the */
/* available fonts. */
/* */
void TextDump()
{
for( Textfont=0 ; Textfont<5 ; ++Textfont ){ /* For each available font */
//DrawAndPrint(TextDump2,NULL);
} /* End of FONT loop */
}
/* */
/* BAR3DDEMO: Display a 3-D bar chart on the screen. */
/* */
int Bar3DDemo(void far * UnusedPointer)
{
static int barheight[] = {
1, 3, 5, 4, 3, 2, 1, 5, 4, 2, 3 };
struct viewporttype vp;
int xstep, ystep;
int i, j, h, color, bheight;
char buffer[10];
MainWindow( "Bar 3-D / Rectangle Demonstration" );
srand(0);
h = 3 * textheight( "H" );
getviewsettings( &vp );
settextjustify( CENTER_TEXT, TOP_TEXT );
changetextstyle( TRIPLEX_FONT, HORIZ_DIR, 4 );
outtextxy( MaxX/2, 6, "These are 3-D Bars" );
changetextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
setviewport( vp.left+50, vp.top+40, vp.right-50, vp.bottom-10, 1 );
getviewsettings( &vp );
line( h, h, h, vp.bottom-vp.top-h );
line( h, (vp.bottom-vp.top)-h, (vp.right-vp.left)-h, (vp.bottom-vp.top)-h );
xstep = ((vp.right-vp.left) - (2*h)) / 10;
ystep = ((vp.bottom-vp.top) - (2*h)) / 5;
j = (vp.bottom-vp.top) - h;
settextjustify( CENTER_TEXT, CENTER_TEXT );
for( i=0 ; i<6 ; ++i ){
line( h/2, j, h, j );
itoa( i, buffer, 10 );
outtextxy( 0, j, buffer );
j -= ystep;
}
j = h;
settextjustify( CENTER_TEXT, TOP_TEXT );
for( i=0 ; i<11 ; ++i ){
color = random( MaxColors-1 ) +1;
setfillstyle( i+1, color );
line( j, (vp.bottom-vp.top)-h, j, (vp.bottom-vp.top-3)-(h/2) );
itoa( i, buffer, 10 );
outtextxy( j, (vp.bottom-vp.top)-(h/2), buffer );
if( i != 10 ){
bheight = (vp.bottom-vp.top) - h - 1;
bar3d( j, (vp.bottom-vp.top-h)-(barheight[i]*ystep), j+xstep, bheight,
min(getmaxy(),getmaxx())/25, 1 );
}
j += xstep;
}
Pause(); /* Pause for user's response */
return(0);
}
/* */
/* RANDOMBARS: Display random bars */
/* */
int RandomBars(void far * UnusedPointer)
{
int color;
int i;
MainWindow( "Random Bars" );
/* StatusLine( "Esc aborts or press a key..." ); */
srand(0);
for ( i=0; i<10; i++ )
{
color = random( MaxColors-1 )+1;
setcolor( color );
s